package com.quick.develop.flowable.framework.cmd;

import com.quick.develop.framework.utils.StringUtils;
import org.flowable.common.engine.impl.interceptor.Command;
import org.flowable.common.engine.impl.interceptor.CommandContext;
import org.flowable.common.engine.impl.persistence.deploy.DeploymentCache;
import org.flowable.engine.impl.persistence.deploy.DeploymentManager;
import org.flowable.engine.impl.persistence.deploy.ProcessDefinitionCacheEntry;
import org.flowable.engine.impl.util.CommandContextUtil;
import org.flowable.engine.repository.Deployment;

import java.io.Serializable;

/**
 * desc:
 *
 * @author junyuan.liu
 * @date 2023/3/22 14:31
 */
public class DeploymentCacheCmd implements Command<Deployment>, Serializable {

    private static final long serialVersionUID = -356382942824442069L;

    private final String definitionId;

    public DeploymentCacheCmd(String definitionId) {
        this.definitionId = definitionId;
    }

    @Override
    public Deployment execute(CommandContext commandContext) {
        DeploymentManager deploymentManager = CommandContextUtil.getProcessEngineConfiguration().getDeploymentManager();
        DeploymentCache<ProcessDefinitionCacheEntry> deploymentCache = deploymentManager.getProcessDefinitionCache();
        if(StringUtils.isNotEmpty(definitionId)) {
            // 清除指定缓存
            deploymentCache.remove(definitionId);
        }
        return null;
    }
}
